package org.springframework.beans.factory.test.annoTest;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.PropertyValue;
import org.springframework.beans.factory.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.List;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/7/25
 */

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition(MyFactoryBean.class);
		genericBeanDefinition.setResolvedAutowireMode(BeanFactory.AUTOWIRE_CONSTRUCTOR);
		List<PropertyValue> pvs = new ArrayList<>();
		pvs.add(new PropertyValue("clazz",UserMapper.class));
		genericBeanDefinition.setConstructorArgumentPropertyValues(pvs);
		registry.registerBeanDefinition("userMapper",genericBeanDefinition);
	}
}
